package design.mode.dispatcher.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import java.util.stream.Collectors;

/**
 * 生成唯一id
 * @author ldanniel
 */
public class GenerateIdUtils {
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            System.out.println(generateValue());
        }
    }
    public static String generateUniqueId(){
        long currentTimeMillis = System.currentTimeMillis();
        Random random = new Random();

        // 使用当前时间作为前缀
        String prefix = String.valueOf(currentTimeMillis);

        // 如果当前时间戳不足13位，则填充0
        while (prefix.length() < 13) {
            prefix = "0" + prefix;
        }

        // 生成一个6位的随机数作为后缀
        int suffix = random.nextInt(1_000_000); // 从0到999999
        String suffixStr = String.format("%06d", suffix); // 确保始终有6位，不足则补0

        // 组合前缀和后缀得到最终的19位数字
        return prefix + suffixStr;
    }

    public static double generateValue(){
        Random random = new Random((int) (Math.random()*5000));
        return Double.parseDouble(String.valueOf(random.nextDouble() * 10).substring(0,5));
    }
    public static double generatePercent(){
        return generateValue()*10;
    }
}
